package com.qyer.search.model;

import static com.qyer.commons.utils.CommonUtils.cast2Int;
import static com.qyer.commons.utils.CommonUtils.cast2String;

import org.apache.commons.collections4.MapUtils;

import java.util.Map;

/**
 * Created by tangzheng on 16/3/8.
 */
public class Channel {
  public static final String FIELD_NAME = "channel";
  private String channel;

  public Channel(String channel) {
    this.channel = channel;
  }

  @Override public boolean equals(Object o) {
    if (this == o)
      return true;
    if (o == null || getClass() != o.getClass())
      return false;

    Channel channel1 = (Channel) o;

    return channel.equals(channel1.channel);

  }

  @Override public int hashCode() {
    return channel.hashCode();
  }

  @Override public String toString() {
    return "Channel{" +
      "channel='" + channel + '\'' +
      '}';
  }

  public String getChannel() {
    return channel;
  }

  public void setChannel(String channel) {
    this.channel = channel;
  }

  public static Channel buildChannel(Map<String, Object> dataMap) {
    if (MapUtils.isEmpty(dataMap)) {
      return null;
    }

    String channel = cast2String(dataMap.get(FIELD_NAME));

    return new Channel(channel);
  }
}
